program on JRadioButtons using applets
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class radio extends JApplet implements ActionListener
{
JTextField jtf;
public void init()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
ImageIcon r=new ImageIcon("image1.gif");
JRadioButton b1=new JRadioButton("a");
JRadioButton b2=new JRadioButton("b");
JRadioButton b3=new JRadioButton("c");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
cp.add(b1);
cp.add(b2);
cp.add(b3);
ButtonGroup bg=new ButtonGroup();
bg.add(b1);
bg.add(b2);
bg.add(b3);
jtf=new JTextField(5);
cp.add(jtf);
}
public void actionPerformed(ActionEvent ae)
{
jtf.setText(ae.getActionCommand());
}
}
/*<applet code=radio width=700 height=600>
</applet>*/
write a program to calculate simple mathematical calculations using radiobuttons.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mani11 extends JFrame implements ActionListener,WindowListener
{
JTextField t1,t2,t3;
JRadioButton add,sub,mul,div;
public static void main(String args[])
{
mani11 k=new mani11();
k.setSize(200,200);
k.setVisible(true);
}
mani11()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
JRadioButton add=new JRadioButton("add");
JRadioButton sub=new JRadioButton("sub");
JRadioButton mul=new JRadioButton("mul");
JRadioButton div=new JRadioButton("div");
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
cp.add(add);
cp.add(sub);
cp.add(mul);
cp.add(div);
ButtonGroup bg=new ButtonGroup();
bg.add(add);
bg.add(sub);
bg.add(mul);
bg.add(div);
t1=new JTextField(5);
t2=new JTextField(5);
t3=new JTextField(5);
cp.add(t1);
cp.add(t2);
cp.add(t3);
}
public void windowClosing(WindowEvent e)
{
this.dispose();
}
public void windowClosed(WindowEvent e)
{
}
public void windowOpened(WindowEvent e)
{
}
public void windowActivated(WindowEvent e)
{
}
public void windowDeactivated(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{}
public void windowIconified(WindowEvent e)
{}
public void actionPerformed(ActionEvent ae)
{
int a,b,c=0;
a=Integer.parseInt(t1.getText());
b=Integer.parseInt(t2.getText());
String s=(String)ae.getActionCommand();
if(s.equals("add"))
c=a+b;
else
if(s.equals("sub"))
c=a-b;
else
if(s.equals("mul"))
c=a*b;
else
if(s.equals("div"))
c=a/b;
t3.setText(""+c);
}
}